package com.easoft.code.pos.ui.beans;

import com.easoft.code.pos.App;
import com.easoft.code.pos.data.dao.ComposeEntity;
import com.easoft.code.pos.data.pojos.Bodega;
import com.easoft.code.pos.data.pojos.DocumentoOper;
import com.easoft.code.pos.data.pojos.DocumentoOperTipo;
import com.easoft.code.pos.data.pojos.MovimientoInv;
import com.easoft.code.pos.data.pojos.MovimientoInvDet;
import com.easoft.code.pos.data.pojos.Persona;
import com.easoft.code.pos.data.pojos.Producto;
import com.easoft.code.pos.ui.bind.UIBinder;
import com.easoft.code.pos.ui.controllers.DataEntryController;
import com.easoft.code.pos.ui.controllers.InventariosMovController;
import com.easoft.code.pos.ui.controllers.exception.ControllerException;
import com.easoft.code.pos.ui.controllers.impl.InventoryMovsControllerImpl;
import com.easoft.code.pos.ui.models.PojoTableModel;
import com.easoft.code.pos.util.DataFormatter;
import com.easoft.code.pos.util.UIUtil;
import com.easoft.code.pos.util.Valores;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Eliu
 */
public class FormInventarioMov extends javax.swing.JPanel {

    private final InventariosMovController controller = new InventariosMovController();
    private final InventoryMovsControllerImpl uiController;
    private DocumentoOper selRow = new DocumentoOper();
    private final FormBusquedaClientes dgClientes = new FormBusquedaClientes(App.mainForm, false);
    private PojoTableModel detalleModel;
    private boolean editMode = false;

    public FormInventarioMov(DataEntryController uiController) {
        this.uiController = (InventoryMovsControllerImpl) uiController;
        initComponents();
        prepareUI();
    }

    /**
     *
     * @param oper
     * @param editMode
     */
    public void loadData(DocumentoOper oper, boolean editMode) {
        this.editMode = editMode;
        selRow = oper;
        if (!this.editMode) {
            selRow.setMovimientoInvCollection(
                    selRow.getMovimientoInvCollection() == null ? new LinkedBlockingDeque<MovimientoInv>()
                    : selRow.getMovimientoInvCollection());

        }
        selRow.setDescuento(0f);
        bindUI();
    }

    private void bindUI() {
        try {
            if (selRow.getMovimientoInvCollection() == null || selRow.getMovimientoInvCollection().isEmpty()) {
                selRow.setMovimientoInvCollection(new LinkedList<MovimientoInv>());
                MovimientoInv m = new MovimientoInv();
                m.setDocumentoMovId(selRow);
                m.setFechaEmision(selRow.getFecha());
                m.setPosUsuario(App.currentUser);
                selRow.getMovimientoInvCollection().add(m);
            }
            if (selRow.getMovimientoInvCollection().iterator().next().getMovimientoInvDetCollection() == null) {
                selRow.getMovimientoInvCollection().iterator().next().setMovimientoInvDetCollection(new LinkedList<MovimientoInvDet>());
            }
            if (selRow.getPersonaId() != null) {
                bindPersona(selRow.getPersonaId());
            }
            MovimientoInv m = selRow.getMovimientoInvCollection().iterator().next();

            uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setDoctoOperTipo", DocumentoOperTipo.class), selRow, cmbTipoDocto));
            uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setEstado", Integer.class), selRow, cmbEstadoDocto, true, "Estado"));
            uiController.add2Binder(new UIBinder(m.getClass().getMethod("setBodega", Bodega.class), m, cmbBodega, true, "Bodega"));
            uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setSerie", String.class), selRow, txtSerie, true, "Serie"));
            uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setNumero", Integer.class), selRow, txtNoDocto, true, "Numero"));
            uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setFecha", Date.class), selRow, txtFechaDocto, true, "Fecha"));
            uiController.add2Binder(new UIBinder(m.getClass().getMethod("setFechaEmision", Date.class), m, txtFechaDocto));
            uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setEfectivo", Float.class), selRow, txtEfectivo));
            uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setCredito", Float.class), selRow, txtCredito));
            uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setTarjeta", Float.class), selRow, txtTarjeta));
            uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setCheque", Float.class), selRow, txtCheque));
            uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setTotal", Float.class), selRow, txtTotal));

            detalleModel.setData((List) m.getMovimientoInvDetCollection());
            detalleModel.fireTableDataChanged();
        } catch (NoSuchMethodException | SecurityException ex) {
            Logger.getLogger(FormInventarioMov.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void prepareUI() {
        try {

            cmbTipoDocto.setModel(controller.getListModelByEntity(DocumentoOperTipo.class));            
            cmbBodega.setModel(controller.getListModelByEntity(Bodega.class));
            cmbEstadoDocto.setModel(controller.getEstadosListModel());

            detalleModel = new PojoTableModel(new LinkedList(),
                    Arrays.asList(new String[]{"Producto", "Cantidad", "Precio Venta", "Subtotal"}),
                    Arrays.asList(new String[]{"ProductoCodigo", "Cantidad", "PrecioVenta", "Total"}),
                    MovimientoInvDet.class, new Integer[]{1, 2}) {

                        @Override
                        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
                            super.setValueAt(aValue, rowIndex, columnIndex);
                            Object other = super.getValueAt(rowIndex, columnIndex == 1 ? 2 : 1);
                            super.setValueAt(Double.valueOf(other.toString()) * Double.valueOf(aValue.toString()), rowIndex, 3);
                            detalleModel.fireTableDataChanged();
                            setTotal();
                        }

                    };
            movDetailTable.setModel(detalleModel);
            txtFechaDocto.setDateFormatString(Valores.getConfigValue(Valores.DATE_FORMAT));
        } catch (ControllerException ex) {
            Logger.getLogger(FormInventarioMov.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     *
     * @param p
     */
    private void addProducto(Producto p) {
        MovimientoInvDet d = new MovimientoInvDet();
        d.setProductoCodigo(p);
        d.setCantidad(1f);
        d.setDescuentoAuto(0f);
        d.setGanancia(0f);
        d.setPrecioCosto(p.getPrecioCosto());
        d.setPrecioVenta(p.getPrecioCosto());
        d.setPrecioCosto(p.getPrecioCosto() != null ? p.getPrecioCosto() : 0f);
        d.setTotal(d.getPrecioCosto() * d.getCantidad());
        d.setTotalNeto(d.getTotal());
        txtTotal.setText(DataFormatter.formatNumber(Float.valueOf(txtTotal.getText()) + d.getTotal().doubleValue()));
        d.setMovimientoInvId(selRow.getMovimientoInvCollection().iterator().next());
        ((MovimientoInv) selRow.getMovimientoInvCollection().iterator().next()).getMovimientoInvDetCollection().add(d);
        detalleModel.fireTableDataChanged();
    }

    /**
     *
     * @param idx
     */
    private void delProducto(int idx) {
        List<MovimientoInvDet> detalles = (List<MovimientoInvDet>) ((MovimientoInv) selRow.getMovimientoInvCollection().iterator().next()).getMovimientoInvDetCollection();
        MovimientoInvDet d = (MovimientoInvDet) detalles.get(idx);
        txtTotal.setText(DataFormatter.formatNumber(d.getTotal().doubleValue() - Float.valueOf(txtTotal.getText())));
        detalleModel.fireTableDataChanged();
    }

    private void validateTotal() {
        try {
            float total = Float.valueOf(txtEfectivo.getText()) + Float.valueOf(txtTarjeta.getText())
                    + Float.valueOf(txtCheque.getText()) + Float.valueOf(txtCredito.getText());
            if (total != NumberFormat.getInstance().parse(txtTotal.getText()).floatValue()) {
                UIUtil.showError("Error: Los montos pagados no deben ser mayores al total!", "Movimiento Inventarios");
            }
        } catch (ParseException ex) {
            UIUtil.showError("Error de valores! " + ex.getMessage(), "Movimiento Inventarios");
        }
    }

    private void setTotal() {
        List<MovimientoInvDet> detalles = (List<MovimientoInvDet>) ((MovimientoInv) selRow.getMovimientoInvCollection().iterator().next()).getMovimientoInvDetCollection();
        float total = 0f;
        for (MovimientoInvDet d : detalles) {
            total += d.getTotal();
        }
        txtTotal.setText(DataFormatter.formatNumber(total));
    }

    /**
     *
     * @param p
     */
    private void bindPersona(Persona p) {
        selRow.getForeingEntities().clear();
        selRow.setPersonaId(p);
        selRow.setPersonaTipo(p.getTipoPersona());
        txtNombrePersona.setText(p.getNombre().isEmpty() ? p.getRazonSocial() : p.getNombre());
        txtDireccionPersona.setText(p.getDireccion());
        txtCodPersona.setText(p.getCodigo());
        if (p.getTipoPersona() == 1) {
            rdBtnCliente.setSelected(true);
        } else {
            rdBtnProveedor.setSelected(true);
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        grpTipoPersona = new javax.swing.ButtonGroup();
        inputsPanel = new javax.swing.JPanel();
        cmbTipoDocto = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtNoDocto = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtCodPersona = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtNombrePersona = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtDireccionPersona = new javax.swing.JTextField();
        txtBtnLov = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtSerie = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        cmbBodega = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        txtEfectivo = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtCredito = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtTarjeta = new javax.swing.JTextField();
        txtTotal = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        cmbEstadoDocto = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        txtCheque = new javax.swing.JTextField();
        txtFechaDocto = new com.toedter.calendar.JDateChooser();
        rdBtnCliente = new javax.swing.JRadioButton();
        rdBtnProveedor = new javax.swing.JRadioButton();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        btnAddLinea = new javax.swing.JButton();
        btnDelLinea = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        movDetailTable = new javax.swing.JTable();

        setLayout(new java.awt.BorderLayout());

        inputsPanel.setPreferredSize(new java.awt.Dimension(462, 315));
        inputsPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cmbTipoDocto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbTipoDocto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTipoDoctoActionPerformed(evt);
            }
        });
        inputsPanel.add(cmbTipoDocto, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 10, 160, -1));

        jLabel1.setText("Tipo Mov.:");
        inputsPanel.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, -1));

        jLabel2.setText("Numero:");
        inputsPanel.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 40, -1, -1));
        inputsPanel.add(txtNoDocto, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 40, 100, -1));

        jLabel3.setText("NIT/DPI:");
        inputsPanel.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 120, -1, -1));

        txtCodPersona.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCodPersonaFocusLost(evt);
            }
        });
        inputsPanel.add(txtCodPersona, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 120, 100, -1));

        jLabel4.setText("Nombre:");
        inputsPanel.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 150, -1, -1));

        txtNombrePersona.setEditable(false);
        inputsPanel.add(txtNombrePersona, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 150, 220, -1));

        jLabel5.setText("Direccion:");
        inputsPanel.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 180, -1, -1));

        txtDireccionPersona.setEditable(false);
        txtDireccionPersona.setToolTipText("");
        inputsPanel.add(txtDireccionPersona, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 180, 220, -1));

        txtBtnLov.setText("...");
        txtBtnLov.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtBtnLovActionPerformed(evt);
            }
        });
        inputsPanel.add(txtBtnLov, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 120, 21, 20));

        jLabel6.setText("Fecha:");
        inputsPanel.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 70, -1, -1));

        jLabel7.setText("Serie:");
        inputsPanel.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 10, -1, -1));
        inputsPanel.add(txtSerie, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 10, 100, -1));

        jLabel8.setText("Bodega");
        inputsPanel.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, -1, -1));

        cmbBodega.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        inputsPanel.add(cmbBodega, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 40, 160, -1));

        jLabel9.setText("Efectivo:");
        inputsPanel.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 240, -1, -1));

        txtEfectivo.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtEfectivo.setText("0.00");
        txtEfectivo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtEfectivoFocusLost(evt);
            }
        });
        inputsPanel.add(txtEfectivo, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 240, 93, -1));

        jLabel10.setText("Credito:");
        inputsPanel.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 240, -1, -1));

        txtCredito.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtCredito.setText("0.00");
        txtCredito.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCreditoFocusLost(evt);
            }
        });
        inputsPanel.add(txtCredito, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 240, 93, -1));

        jLabel11.setText("Tarjeta:");
        inputsPanel.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 240, -1, -1));

        txtTarjeta.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTarjeta.setText("0.00");
        txtTarjeta.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtTarjetaFocusLost(evt);
            }
        });
        inputsPanel.add(txtTarjeta, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 240, 93, -1));

        txtTotal.setEditable(false);
        txtTotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTotal.setText("0.00");
        inputsPanel.add(txtTotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 270, 93, -1));

        jLabel12.setText("Total:");
        inputsPanel.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 270, -1, -1));

        jLabel13.setText("Estado:");
        inputsPanel.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, 60, -1));

        cmbEstadoDocto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbEstadoDocto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbEstadoDoctoActionPerformed(evt);
            }
        });
        inputsPanel.add(cmbEstadoDocto, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 70, 120, -1));

        jLabel14.setText("Cheque:");
        inputsPanel.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 270, -1, -1));

        txtCheque.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtCheque.setText("0.00");
        txtCheque.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtChequeFocusLost(evt);
            }
        });
        inputsPanel.add(txtCheque, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 270, 93, -1));
        inputsPanel.add(txtFechaDocto, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 70, -1, -1));

        grpTipoPersona.add(rdBtnCliente);
        rdBtnCliente.setText("Cliente");
        rdBtnCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdBtnClienteActionPerformed(evt);
            }
        });
        inputsPanel.add(rdBtnCliente, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 150, 80, -1));

        grpTipoPersona.add(rdBtnProveedor);
        rdBtnProveedor.setText("Proveedor");
        inputsPanel.add(rdBtnProveedor, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 180, -1, -1));

        add(inputsPanel, java.awt.BorderLayout.PAGE_START);

        jPanel4.setLayout(new java.awt.BorderLayout());

        jPanel5.setLayout(new java.awt.FlowLayout(1, 1, 1));

        btnAddLinea.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add-4.png"))); // NOI18N
        btnAddLinea.setText("Nuevo");
        btnAddLinea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddLineaActionPerformed(evt);
            }
        });
        jPanel5.add(btnAddLinea);

        btnDelLinea.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon-16-delete.png"))); // NOI18N
        btnDelLinea.setText("Quitar");
        btnDelLinea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDelLineaActionPerformed(evt);
            }
        });
        jPanel5.add(btnDelLinea);

        jPanel4.add(jPanel5, java.awt.BorderLayout.PAGE_START);

        jScrollPane1.setPreferredSize(new java.awt.Dimension(452, 350));

        movDetailTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        movDetailTable.setCellSelectionEnabled(true);
        movDetailTable.setRowHeight(20);
        jScrollPane1.setViewportView(movDetailTable);

        jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        add(jPanel4, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void txtBtnLovActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBtnLovActionPerformed
        dgClientes.setVisible(true);
        bindPersona(dgClientes.getSelRow());

    }//GEN-LAST:event_txtBtnLovActionPerformed

    private void btnAddLineaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddLineaActionPerformed
        FormPOSBusquedaProds frmBusqueda = new FormPOSBusquedaProds();
        addProducto(frmBusqueda.getSelProduct());
    }//GEN-LAST:event_btnAddLineaActionPerformed

    private void txtCodPersonaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCodPersonaFocusLost
        Persona p = dgClientes.findPersonByCode(txtCodPersona.getText());
        if (p == null) {
            try {
                UIUtil.showMsg("El codigo de persona no existe!\nSe agregara automaticamente al sistema.", "Movimientos Inventarios");
                p = new Persona();
                p.setTipoPersona(1);
                p.setCodigo(txtCodPersona.getText());
                p.setTelefono("");
                selRow.setPersonaId(p);
                ((ComposeEntity) selRow).getForeingEntities().add(p);
                uiController.add2Binder(new UIBinder(selRow.getPersonaId().getClass().getMethod("setNombre", String.class), selRow.getPersonaId(), txtNombrePersona));
                uiController.add2Binder(new UIBinder(selRow.getPersonaId().getClass().getMethod("setDireccion", String.class), selRow.getPersonaId(), txtNombrePersona));
                uiController.add2Binder(new UIBinder(selRow.getPersonaId().getClass().getMethod("setTipoPersonaFromBinder", String.class), selRow.getPersonaId(), rdBtnCliente));
                uiController.add2Binder(new UIBinder(selRow.getPersonaId().getClass().getMethod("setTipoPersonaFromBinder", String.class), selRow.getPersonaId(), rdBtnProveedor));
                uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setTipoPersonaFromBinder", String.class), selRow, rdBtnCliente));
                uiController.add2Binder(new UIBinder(selRow.getClass().getMethod("setTipoPersonaFromBinder", String.class), selRow, rdBtnProveedor));
                txtNombrePersona.setEditable(true);
                txtDireccionPersona.setEditable(true);
                rdBtnCliente.setSelected(true);
                inputsPanel.validate();
            } catch (NoSuchMethodException | SecurityException ex) {
                Logger.getLogger(FormInventarioMov.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            bindPersona(p);
        }
    }//GEN-LAST:event_txtCodPersonaFocusLost

    private void btnDelLineaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelLineaActionPerformed
        delProducto(movDetailTable.getSelectedRow());
    }//GEN-LAST:event_btnDelLineaActionPerformed

    private void cmbTipoDoctoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTipoDoctoActionPerformed
        DocumentoOperTipo dTipo = (DocumentoOperTipo) cmbTipoDocto.getSelectedItem();
        txtNoDocto.setEditable(true);
        txtSerie.setEditable(true);
        if (dTipo.getNumeroAutomatico() == 1) {
            txtNoDocto.setEditable(false);
            txtSerie.setEditable(false);
            txtNoDocto.setText(controller.getNextDocNumber(dTipo.getDocumentoResolucion()) + "");
            txtSerie.setText(dTipo.getDocumentoResolucion().toUpperCase());
        }
        if (dTipo.getFechaAutomatica() == 1) {
            txtFechaDocto.setDate(Calendar.getInstance().getTime());
            txtFechaDocto.setEnabled(false);
        }

    }//GEN-LAST:event_cmbTipoDoctoActionPerformed

    private void cmbEstadoDoctoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbEstadoDoctoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbEstadoDoctoActionPerformed

    private void txtEfectivoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtEfectivoFocusLost
        validateTotal();
    }//GEN-LAST:event_txtEfectivoFocusLost

    private void txtCreditoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCreditoFocusLost
        validateTotal();
    }//GEN-LAST:event_txtCreditoFocusLost

    private void txtTarjetaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtTarjetaFocusLost
        validateTotal();
    }//GEN-LAST:event_txtTarjetaFocusLost

    private void txtChequeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtChequeFocusLost
        validateTotal();
    }//GEN-LAST:event_txtChequeFocusLost

    private void rdBtnClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdBtnClienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rdBtnClienteActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddLinea;
    private javax.swing.JButton btnDelLinea;
    private javax.swing.JComboBox cmbBodega;
    private javax.swing.JComboBox cmbEstadoDocto;
    private javax.swing.JComboBox cmbTipoDocto;
    private javax.swing.ButtonGroup grpTipoPersona;
    private javax.swing.JPanel inputsPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable movDetailTable;
    private javax.swing.JRadioButton rdBtnCliente;
    private javax.swing.JRadioButton rdBtnProveedor;
    private javax.swing.JButton txtBtnLov;
    private javax.swing.JTextField txtCheque;
    private javax.swing.JTextField txtCodPersona;
    private javax.swing.JTextField txtCredito;
    private javax.swing.JTextField txtDireccionPersona;
    private javax.swing.JTextField txtEfectivo;
    private com.toedter.calendar.JDateChooser txtFechaDocto;
    private javax.swing.JTextField txtNoDocto;
    private javax.swing.JTextField txtNombrePersona;
    private javax.swing.JTextField txtSerie;
    private javax.swing.JTextField txtTarjeta;
    private javax.swing.JTextField txtTotal;
    // End of variables declaration//GEN-END:variables
}
